# -*- coding: utf-8 -*-
import os,shutil

def movefile(srcfile,dstfile):
    fpath,fname=os.path.split(srcfile)
    if os.path.isfile(os.path.join(dstfile,fname)):
        print("%s exist!"%str(os.path.join(dstfile,fname)))
    elif not os.path.isfile(srcfile):
        print("%s not exist!")%(srcfile)
    else:
        fpath,fname=os.path.split(dstfile)
        if not os.path.exists(fpath):
            os.makedirs(fpath)
        shutil.move(srcfile,dstfile)

def getfile(path):
    paths = []
    for root, dirs, files in os.walk(path):
        for file in files:
            paths.append(os.path.join(root,file))
    return paths

def main():
    path = "/path/A"
    pathto = "/path/B"
    paths = getfile(path)
    for pathfrom in paths:
        print(pathfrom)
        movefile(pathfrom,pathto)

if __name__ == '__main__':
    main()